package classfile

type MemberInfo struct {
	Cp ConstantPool
	AccessFlags uint16
	NameIndex uint16
	DescriptoIndex uint16
	Attributes []AttributeInfo
}

func (self *MemberInfo)Name() string {
	return self.Cp.getUtf8(self.NameIndex)
}

func (self *MemberInfo)Descriptor() string {
	return self.Cp.getUtf8(self.DescriptoIndex)
}

func readMembers(reader *ClassReader, cp ConstantPool) []*MemberInfo {
	count := reader.ReadUint16()
	members := make([]*MemberInfo, count)
	for i := range members {
		members[i] = readMember(reader, cp)
	}
	return nil
}

func readMember(reader *ClassReader, cp ConstantPool) *MemberInfo {
	return &MemberInfo{
		Cp:cp,
		AccessFlags: reader.ReadUint16(),
		NameIndex: reader.ReadUint16(),
		DescriptoIndex:reader.ReadUint16(),
		Attributes:readAttributes(reader, cp),
	}
}

/*

 */
func (self *MemberInfo) CodeAttribute() *CodeAttribute {
	for _, attrInfo := range self.Attributes {
		switch attrInfo.(type) {
		case *CodeAttribute:
			return attrInfo.(*CodeAttribute)
		}
	}
	return nil
}

func (self *MemberInfo) ConstantValueAttribute() *ConstantValueAttribute {
	for _, attrInfo := range self.Attributes {
		switch attrInfo.(type) {
		case *ConstantValueAttribute:
			return attrInfo.(*ConstantValueAttribute)
		}
	}
	return nil
}

